package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.adapters.ArticlesAdapter.ViewHolder;
import com.ykdl.member.kid.beans.ArticleBean;
import com.ykdl.member.kid.beans.StoreInfoBean;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MyCardAdapter extends BaseAdapter{

	private ArrayList<StoreInfoBean>   list;
	private BitmapUtils bitmapUtil ;
	private Context mContext ;
	final int[] storecard_res = {R.drawable.sc_bg9, R.drawable.sc_bg10, R.drawable.sc_bg11
			, R.drawable.sc_bg12, R.drawable.sc_bg13};
	public MyCardAdapter(Context context){
		mContext = context;
		bitmapUtil = new BitmapUtils(context);
		bitmapUtil.configDefaultLoadingImage(R.drawable.defult_head_icon);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defult_head_icon);
	}
	
	public void setList(ArrayList<StoreInfoBean> list) {
		this.list = list;
		
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list==null) {
			return 0;
		}else {
			return list.size();
		}
		
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		Log.e("alan", "-------getItem------arg0:"+arg0);
		if (getCount() != 0) {
			return list.get(arg0-1);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = RelativeLayout.inflate(mContext,
					R.layout.mygoodlifeadapter_list_item, null);
			holder = new ViewHolder();
			holder.store_card_bg = (LinearLayout) convertView.findViewById(R.id.store_card_bg);
			holder.store_name = (TextView) convertView.findViewById(R.id.store_name);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.store_name.setText(list.get(position).getStore_name());
		if(list.size()==1){//
			holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg9);
		}else{
			if(position==0){
				holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg1);
			}else if(position==list.size()-1){
				if(position%5==1){
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg8);
				}else if(position%5==2){
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg7);
				}else if(position%5==3){
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg6);
				}else if(position%5==4){
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg5);
				}else{
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg14);  //zi 
				}
				holder.store_name.setText("");
			}else{
				switch (position%5) {
				case 0:
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg0);
					break;
				case 1:
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg2);
					break;
				case 2:
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg3);
					break;
				case 3:
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg4);
					break;
				case 4:
					holder.store_card_bg.setBackgroundResource(R.drawable.sc_bg15);
					break;

				default:
					break;
				}
			}
			
		}
		
//		holder.intro.setText(list.get(arg0).getIntro());
//		String url = list.get(arg0).getUrl();
//		bitmapUtil.display(holder.image, url);
		return convertView;
	}
	class ViewHolder {
		LinearLayout store_card_bg;
		TextView store_name;
		TextView title;
		
	}

}
